﻿using Google.Protobuf.WellKnownTypes;
using Newtonsoft.Json;
using S7Simulate.Config;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Xml.Linq;

namespace S7Simulate.Utils
{
    public class CommonbaseConfig
    {
        public static BaseConfig BaseConfig = InitConfig();
        //读取配置文件
        /// <summary>
        /// 初始化配置
        /// </summary>
        /// <returns></returns>
        public static BaseConfig InitConfig()
        {
            if (BaseConfig == null)
            {
                try
                {
                    string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Config\\config.json";
                    string jsonStr = File.ReadAllText(path);
                    var config = JsonConvert.DeserializeObject<BaseConfig>(jsonStr);
                    return config;
                }
                catch (Exception ex)
                {
                    Log4NetHelper.Error($"InitConfig:{ex.Message};{ex.StackTrace}");
                    return new BaseConfig();
                }
            }
            else
            {
                return new BaseConfig();
            }
        }
    }
}
